<template>
  <div class="register-content">
    <h3 class="register__title">
      <img :src="logoIcon" alt="" />
      <span>{{ $t("login.register.requestUse.title") }}</span>
    </h3>
    <div class="register__tips">
      <p>{{ $t("login.register.requestUse.descrption[1]") }}</p>
      <p>{{ $t("login.register.requestUse.descrption[2]") }}</p>
      <p>{{ $t("login.register.requestUse.descrption[3]") }}</p>
    </div>
    <div class="line"></div>
    <el-form>
      <el-form-item :label="$t('label.mobile')" required>
        <el-input
          v-model="form.mobile"
          :placeholder="$t('placeholder.mobile')"
          class="input-with-select"
          size="large"
          @input="validator(form.mobile)"
        >
          <template #prepend>
            <select-list-mobile-prefix v-model="select" />
          </template>
          <template #suffix>
            <i v-show="form.iconFlag" :class="`iconfont ${form.icon}`"></i>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item label="" label-width="50px">
        <slider-verification
          :move-flag="form.moveFlag"
          @success="success"
        ></slider-verification>
      </el-form-item>
      <el-form-item label="" label-width="50px">
        <div
          class="register__btn"
          :class="{ 'register__btn--active': form.submitBtn }"
          @click="submit"
        >
          {{ $t("login.register.nextStep") }}
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>
<script setup>
import logoIcon from "@/assets/images/logo_icon.png";
import { SelectListMobilePrefix } from "@/components/select-banner";
import { validatorMobile } from "@/utils/regular";
import { SliderVerification } from "@/components";
</script>
<script>
export default {
  data() {
    return {
      form: {
        mobile: "",
        icon: "",
        iconFlag: false,
        moveFlag: false,
        submitBtn: false,
      },
      select: "+86",
    };
  },
  methods: {
    submit() {
      if (this.form.submitBtn) {
        this.$emit("nextStep", "login-info", {
          prefix: this.select,
          number: this.form.mobile,
        });
      } else {
        ElMessage({
          message: this.$t("login.register.requestUse.verification.message"),
          type: "warning",
        });
      }
    },
    success(data) {
      if (data) {
        this.form.submitBtn = data;
      }
    },
    validator() {
      if (this.form.mobile) {
        this.form.iconFlag = true;
        if (!validatorMobile(this.form.mobile)) {
          this.form.icon = "ic-circle-wrong-fill";
          this.form.moveFlag = false;
        } else {
          this.form.icon = "ic-circle-correct-fill";
          this.form.moveFlag = true;
        }
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.register-content {
  width: 100%;
  height: 100%;
  padding: 56px 64px;
}
.register {
  &__title {
    font-size: 32px;
    margin-bottom: 24px;
    @include flex-y-center;
    img {
      margin-right: 16px;
      width: 40px;
      height: 40px;
    }
  }
  &__tips {
    line-height: 24px;
    color: map-get($map: $font-sizes, $key: text);
  }
  .line {
    width: 100%;
    height: 1px;
    background: map-get($map: $fill-color, $key: deep);
    margin: 35px 0;
  }
  .el-form-item {
    --el-color-white: #f2f3f5;
    margin-bottom: 16px;
    :deep(.el-form-item__label) {
      line-height: 40px;
    }
    :deep(.el-form-item__content) {
      flex: inherit;
      width: 400px;
    }
    :deep(.el-input__inner) {
      border: none;
      color: map-get($font-sizes, title);
    }
    :deep(.el-input-group__prepend) {
      border: none;
      --el-bg-color: rgba(242, 243, 245, 1);
      position: relative;
      &::after {
        display: inline-block;
        content: "";
        width: 1px;
        height: 22px;
        position: absolute;
        right: 0;
        top: 50%;
        margin-top: -11px;
        background: map-get($map: $fill-color, $key: deep);
      }
      .el-input__inner {
        padding: 0 0.2rem;
      }
    }
    .el-input__prefix {
      left: 12px;
    }
    i {
      height: 40px;
      line-height: 40px;
      color: map-get($font-sizes, text);
    }
    .el-input__validateIcon {
      display: none;
    }
    .ic-circle-correct-fill {
      color: map-get($map: $status-success, $key: static);
    }
    .ic-circle-wrong-fill {
      color: #f53f3f;
    }
  }
  &__btn {
    width: 400px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    border-radius: 2px;
    color: map-get($font-sizes, white);
    background: map-get($bg-primary, disabled);
  }
  &__btn--active {
    background: map-get($bg-primary, active);
    cursor: pointer;
  }
  &__forget-pwd {
    width: 100%;
    color: map-get($font-sizes, smTitle);
    text-align: center;
    @include absolute-left-bottom-0();
    bottom: 40px;
  }
}
</style>
